﻿using System;
using System.ComponentModel;
using DL.Core.EfCore;
using DL.Core.EfCore.engine;
using DL.Core.EfCore.SqlServer;
using DL.Core.ulitity.attubites;
using DL.Core.ulitity.ui;
using Microsoft.EntityFrameworkCore;
using Microsoft.EntityFrameworkCore.Metadata.Builders;
using Microsoft.Extensions.DependencyInjection;

namespace ConsoleApp1
{
    class Program
    {
        static void Main(string[] args)
        {
            IServiceCollection service = new ServiceCollection();
            service.EnableAutoMigration(false);
            service.AddEnginePack<MyContext>();
            IServiceProvider provider = service.BuildServiceProvider();
            var servicedata = provider.GetService<ITeacherService>();
            servicedata.CreateUser();
            Console.ReadKey();
          
        }
    }
    public class MyContext : DefaultDbContext<MyContext>
    {
        public override string ConnectionString => "Data Source=.;Initial Catalog=VueAdmin;Integrated Security=True";
    }
    public  class TeacherInfo:EntityBase
    {
        [Description("教师名称")]
        public string TeacherName { get; set; }
    }
    public class TeacherInfoConfigration : ConfigurationBase<TeacherInfo>
    {
        public override Type DbContextType => typeof(MyContext);

        public override void Configure(EntityTypeBuilder<TeacherInfo> builder)
        {
            builder.ToTable("TeacherInfo");
        }
    }
    public interface ITeacherService
    {
        void CreateUser();
    }
    [DependencyAttbuite(ServiceLifetime.Scoped)]
    public class TeacerService : ITeacherService
    {
        private IRepository<TeacherInfo> _repository;
        public TeacerService(IRepository<TeacherInfo>  repository)
        {
            _repository = repository;
        }
        public void CreateUser()
        {
            _repository.AddEntity(new TeacherInfo
            {
                 TeacherName = "ppp"
            });
        }
    }
}
